package site.yunnong.atvris.portal.spider.haokan;

import com.geccocrawler.gecco.pipeline.Pipeline;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import site.yunnong.atvris.portal.spider.VideoImportService;

import javax.annotation.Resource;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zjh
 * @date 2021/8/31 11:17
 */
@Slf4j
@Service("haokanVideoPipeline")
//@PipelineName("haokanVideoPipeline")
public class HaokanVideoPipeline implements Pipeline<HaokanVideo> {

    public static Pattern pattern = Pattern.compile("http(s)?:\\\\/\\\\/([\\w-]+\\.)+[\\w-]+(\\\\/[\\w-.\\\\/?%&=]*)?.mp4");
    
    @Resource(name = "haokanVideoImportServiceImpl")
    private VideoImportService service;
    
    @Override
    public void process(HaokanVideo bean) {
        Matcher matcher = pattern.matcher(bean.getScript());
        if (matcher.find()) {
            bean.setUrl(matcher.group().replace("\\", ""));
        }
        service.importVideo(bean);
    }
}
